<template>
  <div class="page-main" v-title data-title="项目绩点转得分系数维护表">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>项目绩点转得分系数维护表</span></div>
    <div class="container">
     <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="12">
              <a-form-item label="项目等级">
                <a-input placeholder="输入项目等级模糊查询" v-model="queryParam.projectLevel"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="绩点类别">
                <a-select   v-model="queryParam.gradePointType" placeholder="请选择绩点类别" >
                  <a-select-option v-for="codeInfo in gradePointTypeList" :value="codeInfo.code" :key="codeInfo.code" :title="codeInfo.name" >{{ codeInfo.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('项目等级所得绩点与得分转换关系')">导出</a-button>
      <a-button   type="primary" icon="import" @click="importExcelDataBtn">导入</a-button>
      <a-button   type="primary" icon="delete" @click="batchDel">删除</a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,columnWidth:1}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>
    <LuckSheetPaste :title="'程项目绩点与得分批量导入'" ref="luckSheetPaste" :columnsExcel="columnsExcel"  @handleOkExcel="handleOkExcel" ></LuckSheetPaste>
    <hte-report-pg-score-modal  ref="modalForm" @ok="modalFormOk"></hte-report-pg-score-modal>
  </a-card>
    </div>
    
  </div>

</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HteReportPgScoreModal from './modules/HteReportPgScoreModal'
  import JInput from '@/components/jeecg/JInput'
  import LuckSheetPaste from '@/components/excelPaste/LuckSheetPaste'
  import { httpAction, getAction,postAction } from '@/api/manage'
  import {codeInfoList} from '@/api/codeInfo'
  export default {
    name: 'HteReportPgScoreList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HomeNav: () => import('@/components/layouts/HomeNav'),
      HteReportPgScoreModal,
      JInput,
      LuckSheetPaste
    },
    data () {
      return {
        userinfo: {
          info: this.$store.getters.userInfo,
          module: 'ContractTaskList',
        },
        description: '项目等级所得绩点与得分转换关系管理页面',
        toggleSearchStatus:true,
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'项目等级',
            align:"center",
            dataIndex: 'projectLevel',
            sorter: (a, b) => a.projectLevel - b.projectLevel,
          },
          {
            title:'绩点类别',
            align:"center",
            dataIndex: 'gradePointTypeName'
          },
          {
            title:'转换系数',
            align:"center",
            dataIndex: 'scoreRatio'
          },
          {
            title:'基础奖励',
            align:"center",
            dataIndex: 'baseReward'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/reportCenter/list",
          delete: "/reportCenter/delete",
          deleteBatch: "/reportCenter/deleteBatch",
          exportXlsUrl: "/reportCenter/exportXls",
          importExcelUrl: "reportCenter/importExcel",
           addBatch:'/reportCenter/addBatch',
        },
        dictOptions:{},
        superFieldList:[],
        columnsExcel:[
           {
            title:'项目等级',
            align:"center",
            dataIndex: 'projectLevel'
          },
          {
            title:'绩点类别',
            align:"center",
            dataIndex: 'gradePointTypeName'
          },
          {
            title:'转换系数',
            align:"center",
            dataIndex: 'scoreRatio'
          },
          {
            title:'基础奖励',
            align:"center",
            dataIndex: 'baseReward'
          },
        ],
        gradePointTypeList:[]
      }
    },
    created() {
      this.getSuperFieldList();
      this.initDics();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDics(){
        codeInfoList({type:'工程项目业绩报表绩点类别',pageSize:-1,isdel: 0}).then((res) => {
          if (res.code == 200) {
            this.gradePointTypeList = res.result.records  
          } else {
            this.$message.warning('操作异常:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('操作异常:' + res.message)
        })
      },
      importExcelDataBtn(){
        this.$refs.luckSheetPaste.showModalExcel();
      },
      handleOkExcel(data,excelVm){
        for (let index = 0; index < data.length; index++) {
          const element = data[index];
          
          let gradePointTypeObj = this.gradePointTypeList.find(item=>{
            return item.name == element.gradePointTypeName
          })
          if(!gradePointTypeObj){
             excelVm.handleErroMsg('请输入正确的绩点类别！')
            return 
          }
          element.gradePointType = gradePointTypeObj.code
          let dataCheck = data.filter(item=>{
            return item.projectLevel == element.projectLevel && item.gradePointTypeName == element.gradePointTypeName
          })
          if(dataCheck.length>1){

            excelVm.handleErroMsg(`项目等级${element.projectLevel}、绩点类别${element.gradePointTypeName}重复!`)
            return 
          }
        }

        postAction(this.url.addBatch,data).then(res => {
          
            if(res.code === 200){
              this.$message.success("导入成功");
              excelVm.afterClose()
              this.loadData();
            }else{
              excelVm.handleErroMsg('操作异常:'+res.message);
            }
        }).catch(res=>{
            this.excelConfirmLoading = false;
            excelVm.handleErroMsg('操作异常:'+res.message);           
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'projectLevel',text:'项目等级'})
        fieldList.push({type:'string',value:'gradePointTypeName',text:'绩点类别'})
        fieldList.push({type:'number',value:'scoreRatio',text:'转换系数'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/hte-main.less';
.page-main {
  .banner {
    background-image: url(../../../assets/contract-top.png);
  }
  .container {
    .content-list {
      margin-top: 15px;
    }
  }
  .font-active {
    cursor: pointer;
  }
}
.contentStyle-default {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contentStyle-red {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: red;
}
.contentStyle-yellow {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: burlywood;
}
</style>